package lec09api;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class M {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int n = cin.nextInt();
        Person[] persons = new Person[n];//int => Integer
        for (int i = 0; i < n; i++) {
            persons[i] = new Person(cin.next(), cin.nextInt(), cin.nextInt(), cin.nextInt());
        }
        Arrays.sort(persons, new Comparator<Person>() {
            @Override
            public int compare(Person pa, Person pb) {
                if (pa.year != pb.year) return pa.year - pb.year;
                if (pa.month != pb.month) return pa.month - pb.month;
                return pa.day - pb.day;
            }
        });
        for (Person person : persons) {//for_each
            System.out.println(person.name);
        }
        cin.close();
    }

    static class Person {//field
        String name;
        int year, month, day;

        public Person(String name, int year, int month, int day) {//Constructor
            this.name = name;
            this.year = year;
            this.month = month;
            this.day = day;
        }
    }

}
